package designMode.observerPattern_api;


import java.util.Observable;
import java.util.Observer;

/**
 * @ClassName CurrentConditionsDisplay
 * @Description
 * @Author LIBOFEI
 * @Date 2020/6/15 09:17
 * @Version 1.0
 **/
public class CurrentConditionsDisplay implements DisplayElement, Observer {

    private float temp;
    private float humidity;
    private Observable observable;

    public CurrentConditionsDisplay(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println("Current condition :" + temp + ">>>" + humidity);
    }

    @Override
    public void update(Observable obs, Object arg) {
        if(obs instanceof WeatherData){
            WeatherData weatherData = (WeatherData)obs;
            this.temp = weatherData.getTemperature();
            this.humidity = weatherData.getHumidity();
            display();
        }
    }
}
